authApp.value('page','material_apply');
authApp.controller("applyMController",function($scope,$http,$location,$getQueryString,$splice){
    $scope.preNum=$getQueryString("preNum");
    $scope.isAddM=true;
    $scope.showEdit = false;
    var requestJson={'fid':$getQueryString("pid")};
    $scope.addM=function(){
        $scope.isAddM=false;
    }
    $scope.cancelAddM=function(){
        $scope.isAddM=true;
        $scope.addFZ="";
        $scope.addDesc="";
        $scope.addValue="";
        $scope.P_type = "";
    }

    $scope.addFirstZ=function(){
        if($scope.addFZ){
            var rJson={'name':$scope.addFZ,'desc':$scope.addDesc,'value':$scope.addValue,'fid':$getQueryString("pid"),'type':$scope.P_type};
            $http({
                method:'post',
                url:apis.saveMonitorSeeMap,
                data:rJson,
            }).success(function(response){
                var radom=Math.random();
                if(response.code=="000000"){
                    $scope.isAddM=true;
                    $scope.getAML();
                    $scope.addFZ="";
                    $scope.addRequire = "";
                    $scope.P_type = "";
                }else{
                    alert(response.errorMsg);
                }
            }).error(function(){
                alert("服务器打瞌睡了，请稍等！");
                $scope.isAddM=true;
            })

        }

    }
    //编辑
    $scope.edit = function (item) {
        $scope.item = item;
        $scope.showEdit = true;
    }
    $scope.doEdit = function (item) {
        if(!item.s_name){
            alert("请输入测评点分项");
            return;
        }

        var rJson={'name':item.s_name,'desc':item.s_desc,'value':item.s_value,'pid':item.p_id,'type':item.p_type};

        $http({
            method:'post',
            url:apis.updataMonitorSeeMapInfo,
            data:rJson,
        }).success(function(response){
            if(response.code=="000000"){
                alert("编辑成功");
                $scope.showEdit=false;
                $scope.getAML();
                $scope.item="";
            }else{
                alert(response.errorMsg);
            }
        }).error(function(){
            alert("服务器打瞌睡了，请稍等！");
            $scope.showEdit=false;
        })
    }
    $scope.doCancel = function () {
        $scope.showEdit=false;
    }
    $scope.getAML=function(){
        $http({
            method:'post',
            url:apis.queryAllMonitorSeeMap,
            data:requestJson,
        }).success(function(response){
            if(response.code=="000000"){
                $scope.list=response.data;
                angular.forEach($scope.list,function(data,index,array){
                    data.number = index + 1;
                });
            }else{
                alert(response.errorMsg);
            }
        }).error(function(){
            alert("服务器打瞌睡了，请稍等！");
        })
    }
    $scope.delCollect=function(pid){
        if(window.confirm("是否确定删除？")){
            var rJson={'pid':pid};
            $http({
                method:'post',
                url:apis.deleteMonitorSeeMap,
                data:rJson,
            }).success(function(response){
                if(response.code=="000000"){
                    $scope.getAML();
                }else{
                    alert(response.errorMsg);
                }
            })
        }
    }
    $scope.turnTo=function(pid){
        location.href="monitorSeeMap.html?pid="+pid;
    }
    $scope.getAML();
})
